﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel.Composition;
using Caliburn.Micro.BikeWizard.Events;

namespace Caliburn.Micro.BikeWizard.Views
{
    /// <summary>
    /// Instead of handling these events individually, we could just have implemented IHandle<object>
    /// That would have subscribed to all events (i.e. events inherited from object)
    /// </summary>
    [Export()]
    public class LogViewModel : Screen, IHandle<LogEvent>, IHandle<BikeOrderedEvent>
    {
        #region Public Properties
        private string loggingText = "";
        public string LoggingText
        {
            get
            {
                return loggingText;
            }
            set
            {
                loggingText = value;
                NotifyOfPropertyChange(() => LoggingText);
            }
        }
        #endregion

        #region Private Properties (Services)
        private IEventAggregator eventAggregator { get; set; }
        #endregion

        #region Constructors
        [ImportingConstructor()]
        public LogViewModel(IEventAggregator eventAggregator)
        {
            this.eventAggregator = eventAggregator;

            this.eventAggregator.Subscribe(this);
        }
        #endregion

        #region Event Handling (External)
        /// <summary>
        /// This will handle all Log events (i.e. also all derived types)
        /// </summary>
        /// <param name="evnt"></param>
        public void Handle(LogEvent evnt)
        {
            LoggingText += evnt.ToString() + Environment.NewLine;
        }

        public void Handle(BikeOrderedEvent evnt)
        {
            LoggingText += "*********** " + evnt.ToString() + " ***********" + Environment.NewLine;
        }
        #endregion
    }
}
